package com.own.business.sync.trigger.base.bak.util;

import com.alibaba.fastjson2.JSON;
import com.own.business.sync.trigger.base.bak.entity.SyncTriggerBak;
import com.own.business.sync.trigger.base.bak.mapper.SyncTriggerBakMapper;
import com.own.business.sync.trigger.base.entity.SyncTrigger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * SyncTriggerBakUtil
 *
 * @author chenxueli
 * @date 2024-01-09 17:35:00
 */
@Slf4j
@Component
public class SyncTriggerBakUtil {

    @Resource
    private SyncTriggerBakMapper syncTriggerBakMapper;

    /**
     * 同步的时候的同步异常数据
     *
     * @param data    数据
     * @param message 异常消息
     */
    public void save(SyncTrigger data, String message) {
        try {
            var bak = new SyncTriggerBak(data);
            bak.setMessage(message.length() > 400 ? message.substring(0, 400) : message);
            syncTriggerBakMapper.insert(bak);
        } catch (Exception e) {
            log.info("bak保存失败:{},{}", JSON.toJSONString(data), message);
        }
    }

}
